
<form id="comments_form" action="">
<?php 
	foreach ($comment_fields as $comment_field){
		?>
		<div style="clear:both; width:350px;margin-top:10px;">
			<div style="float:left; width: 120px; text-align: right;padding-top: 5px;"><?php echo $comment_field->getName()?>*</div>
			<div style="float:right;width: 220px;"><input type="text" name="<?php echo $comment_field->getId()?>" id="<?php echo $comment_field->getId()?>" style="width:215px;"></div>

			<div style="clear:both"></div>
			
		</div>
		
		<?php

		
	}
?>
<div id="error_msg2" class="error_msg" style="clear:both; display: none; cursor:pointer;width:350px" onclick="$(this).hide('slow')">
	<div id="msg_text2" ></div>
</div>	

<div style="clear:both; width:350px;margin-top:10px;text-align: right;">
	<a  id="contact_form_formsend" class="button" href="#"><?php echo __("Post comment")?></a>
</div>
<input type="hidden" name="template_id" value="<?php echo $template_id?>">

<?php 
$category_content_ids_str = "";
foreach ($category_content_ids as $category_content_id){
		$category_content_ids_str .= $category_content_id . '-';
}
$category_content_ids_str = substr($category_content_ids_str, 0, strlen($category_content_ids_str) - 1);
?>
<input type="hidden" name="category_content_ids" value="<?php echo $category_content_ids_str?>">


</form>
<div style="clear:both"></div>
      
<script>

function validateCommentsForm(){
	var error_msg = "";
	var valid = true;
	<?php 
	foreach ($comment_fields as $comment_field){
	?>
	if ($('#<?php echo $comment_field->getId()?>').attr('value') == ""){
		error_msg = "<?php echo __("Required field") . ': ' . $comment_field->getName() ?>";
		valid = false;
	}
	
	<?php }?>

	if (error_msg != ""){
		$('#msg_text2').html(error_msg);
		$('#error_msg2').show('fast');
	}
	return valid;
	
}


$("#contact_form_formsend").click(function (event){
	var str=$('form#comments_form').serialize();
    $.ajax({type: 'POST', url:'<?php echo url_for("comments/saveComment")?>', script:true, cache:false, data:  str,
            success: function(data) {
            	/*$('#category_container_div').html(data);
                $('#category_name').attr('value',"");*/
             },
    		beforeSend: function(){
        		if (!validateCommentsForm()){
					return false;
        	}
         	}
     });
             
})
</script>
      
<!--    
<div class="fb-login-button" scope="email,user_checkins">
   Login with Facebook
</div>
 -->       
      